package com.net.xpay.common.manager.impl.notify;

import com.google.common.base.Preconditions;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.xpay.common.dao.notify.ChargeNotifyRecordMapper;
import com.net.xpay.common.domain.notify.ChargeNotifyRecord;
import com.net.xpay.common.manager.notify.ChargeNotifyRecordManager;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.model.search.ChargeNotifyRecordSearchModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;


@Component
public class ChargeNotifyRecordManagerImpl extends AbstractManager<ChargeNotifyRecord> implements ChargeNotifyRecordManager{

    @Autowired
    private ChargeNotifyRecordMapper mapper;


    @Override
    protected BasicMapper<Long, ChargeNotifyRecord> getMapper() {
        return mapper;
    }

    @Override
    public ChargeNotifyRecord findByBatchId(Long batchId) {
        Preconditions.checkArgument(batchId != null);
        ChargeNotifyRecord condition = new ChargeNotifyRecord();
        condition.setPayTransBatchId(batchId);
        return getByCondition(condition);
    }

    @Override
    public List<ChargeNotifyRecord> search(ChargeNotifyRecordSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");
        return nonEmptyList(mapper.search(searchModel, page));
    }

    @Override
    public long searchCount(ChargeNotifyRecordSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.searchCount(searchModel);
    }

    @Override
    public int deleteFinishedRecord(LocalDateTime deadline) {
        Preconditions.checkArgument(deadline != null);
        return mapper.deleteFinishedRecord(deadline);
    }
}
